package cn.u313.lymusic.ui.dialog.loading;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import androidx.annotation.LayoutRes;

import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;


/**
 * 弹窗base 通用
 */
abstract class LoadingBaseDialog extends Dialog {
    /**
     * 布局
     */
    private View registerView;     //
    private Context context;
    public LoadingBaseDialog(@NonNull Context context) {
        super(context);
        this.context = context;
    }

    public LoadingBaseDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    protected LoadingBaseDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }
    public void setLayout(@LayoutRes int id){
        registerView = View.inflate(this.context, id, null);
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        getWindow().setBackgroundDrawableResource(android.R.color.transparent);

        registerView = View.inflate(this.context,  getLayout(), null);
        setContentView(registerView);
        // 这句话起全屏的作用
        getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);

        initView();
        initListener();
    }
    View getView(){
        return registerView;
    }
    abstract void initView();
    abstract int getLayout();
    abstract void initListener();

    @Override
    public void dismiss() {
        super.dismiss();
    }

}
